package Epic;

public class PalindromDate {
	
	public static boolean check(String str){
		if(str.length()!= 8 || (!verfiyDate(str))){
			return false;
		}
		
		String firstPart = str.substring(0,4);
		String SecondPart = str.substring(4);
		
		
		if(firstPart.equals(reverse(SecondPart))){
			return true;
		}
		else{
			return false;
		}
		
	}
	
	public static boolean verfiyDate(String str){
		if(str.length() != 8){
			return false;
		}
		int year = Integer.parseInt(str.substring(4));
		int day = Integer.parseInt(str.substring(2,4));
		int month = Integer.parseInt(str.substring(0,2));
		
		
		
		if(month == 1 || month == 3 || month == 5 || month == 7
				|| month == 8 || month == 10 || month == 12){
			if(day > 0 && day <= 31){
				return true;
			}
		}
		else if(month == 4 || month == 6 || month == 9 || month == 11){
			if(day > 0 && day <= 30){
				return true;
			}
		}
		else if(((year % 4 == 0 && year % 100!= 0) || (year % 400 == 0 && year % 100 == 0))
				&& month == 2){
			if(day > 0 && day <= 29){
				return true;
			}
		}
		
		else if (month == 2){
			if(day > 0 && day <= 28){
				return true;
			}
		} 
		
		else{
			return false;
		}
		
	
	
	return false;
}
	
	public static String reverse(String str){
		if(str == null){
			return "";
		}
		
		String result = "";
		for(int i = 0; i < str.length(); i++){
			result = str.charAt(i) + result;
		}
		
		return result;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		for(int i = 0; i <= 12319999; i++){
			String input = String.format("%08d", i);
			if(check(input)){
			System.out.println(input);
			
			}
		}
			
	}

}
